home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 February / Gamestar_81_2006-02_dvd.iso / Red Shark / Common / Cockpit.script < prev    next >
Text File  |  2002-01-09  |  14KB  |  632 lines

  1. //-------------------------------------------------------------------
  2. //
  3. //  This code is copyright 2001 by G5 Software.
  4. //  Any unauthorized usage, either in part or in whole of this code
  5. //  is strictly prohibited. Violators WILL be prosecuted to the
  6. //  maximum extent allowed by law.
  7. //
  8. //-------------------------------------------------------------------
  9.  
  10. class CCockpit extends CStrings
  11. {
  12.   array StringTable =
  13.     array(
  14.       str_NAVPOINT_SELECTED  // from CStrings
  15.     );
  16.  
  17.   string strSkinFile          = "Common/Cockpit.skin";
  18.   string strWeaponChangeSound = "CWeaponChangeSound";
  19.   string strLockingSound      = "CTargetLockingSound";
  20.   string strLockedSound       = "CTargetLockedSound";
  21.   string strTargetSwitchSound = "CTargetSwitchSound";
  22.   string strObjCompleteSound  = "CObjectiveCompleteSound";
  23.  
  24.   string strLockWeaponName    = str_VIKHR; // from CStrings
  25.   string strNoLockWeaponName  = str_S8;    // from CStrings
  26.   string strKph               = str_Kph;   // from CStrings
  27.  
  28.   array m_UnitClassificators  = array(
  29.       "AntiAir",
  30.       "Tank",
  31.       "GunTower",
  32.       "Tent",
  33.       "AJeep",
  34.       "Refueller",
  35.       "Jeep",
  36.       "Truck",
  37.       "Flak"
  38.     );
  39.  
  40.   array m_UnitNames =
  41.     array(
  42.       str_AntiAir,
  43.       str_Tank,
  44.       str_GunTower,
  45.       str_Tent,
  46.       str_ArmJeep,
  47.       str_Refueller,
  48.       str_Jeep,
  49.       str_Truck,
  50.       str_Flak
  51.     );
  52.  
  53.   void CCockpit()
  54.   {
  55.     // navigation bar
  56.     CreateNavBar("MainNavBar", true);
  57.  
  58.     //
  59.     //  Short range radar
  60.     //
  61.  
  62.     CreateRadar(
  63.       "ShortRangeRadar",
  64.       true,
  65.       1500,
  66.       0.01,                                     // x
  67.       1.0 - (0.01 + 0.08 * 2) / 0.75,           // y
  68.       0.08                                      // radius
  69.     );
  70.  
  71.     SetRadarBackgroundColor("ShortRangeRadar", color(0.0, 0.7, 0.0, 0.6));
  72.  
  73.     SetRadarObjectMarkerColor(
  74.       "ShortRangeRadar",
  75.       color(0.0, 0.8, 0.8),  // friendly objects
  76.       color(1.0, 0.0, 0.0)   // enemy objects
  77.     );
  78.  
  79.     SetRadarEnemyClassificator(
  80.       "ShortRangeRadar",
  81.       "German"
  82.     );
  83.  
  84.     SetRadarTargetMarkerColor(
  85.       "ShortRangeRadar",
  86.       color(1.0, 1.0, 0.0)
  87.     );
  88.  
  89.     //
  90.     //  Long range map
  91.     //
  92.  
  93.     CreateMap("LongRangeMap",
  94.       true,
  95.       4000,
  96.       2000,
  97.       16,
  98.       4000.0,
  99.       0.01,         // x
  100.       0.01 / 0.75,  // y
  101.       0.2           // side size
  102.     );
  103.  
  104.     SetMapObjectMarkerColor(
  105.       "LongRangeMap",
  106.       color(0.0, 0.8, 0.8), // friendly objects
  107.       color(1.0, 0.0, 0.0)  // enemy objects
  108.     );
  109.  
  110.     SetMapEnemyClassificator(
  111.       "LongRangeMap",
  112.       "German"
  113.     );
  114.  
  115.     SetMapTargetMarkerColor(
  116.       "LongRangeMap",
  117.       color(1.0, 1.0, 0.0)
  118.     );
  119.  
  120.     SetMapHeliMarkerColor(
  121.       "LongRangeMap",
  122.       color(0.0, 1.0, 0.0)
  123.     );
  124.  
  125.     //
  126.     //  Target pointer
  127.     //
  128.  
  129.     CreateTargetPointer("TargetPointer", true);
  130.     SetTargetPointerEnemyClassificator("TargetPointer", "German");
  131.  
  132.     SetTargetPointerColors(
  133.       "TargetPointer",
  134.       color(0.0, 0.7, 0.0),
  135.       color(0.8, 0.0, 0.0)
  136.     );
  137.  
  138.     SetTargetPointerLockedColors(
  139.       "TargetPointer",
  140.       color(0.0, 1.0, 0.0),
  141.       color(1.0, 0.2, 0.2)
  142.     );
  143.   }
  144.  
  145.   void InitializeCockpit()
  146.   {
  147.     array points =
  148.       Core_CallFunction(SOID_MissionController, "GetNavPoints");
  149.  
  150.     array descs =
  151.       Core_CallFunction(SOID_MissionController, "GetNavPointsDescriptions");
  152.  
  153.     SetNavPoints("MainNavBar", points, descs);
  154.  
  155.     string skin_file =
  156.       Core_CallFunction(SOID_MissionController, "GetMapSkinFileName");
  157.     LoadMapSkinFile(skin_file);
  158.   }
  159.  
  160.   void OnDisplayMessage(string _message, color _color)
  161.   {
  162.     DisplayMessage(_message, _color);
  163.   }
  164.  
  165.   void OnDisplayMessage(string _message, color _color, int _time, int _line)
  166.   {
  167.     DisplayMessage(_message, _color, _time, _line);
  168.   }
  169.  
  170.   void OnToggleCrosshair(bool _enable)
  171.   {
  172.     ToggleCrosshair(_enable);
  173.   }
  174.  
  175.   void OnToggleTargetDesc(bool _enable)
  176.   {
  177.     ToggleTargetDesc(_enable);
  178.   }
  179. }
  180.  
  181.  
  182. class CDebugCameraCockpit extends CCockpit
  183. {
  184.   // initialize cocpit on mission loaded
  185.   void OnMissionLoaded()
  186.   {
  187.     InitializeCockpit();
  188.     MissionEditorInit();
  189.   }
  190.  
  191.   // Mission Editor functions
  192.   void CreateObject(
  193.     string _ObjectID,
  194.     string _ScriptClass,
  195.     string _ComponentID,
  196.     matrix _Matrix)
  197.   {
  198.     //Core_LogMessage("CreateObject() called");
  199.  
  200.     // call script user's function
  201.     MissionEditorCreateObject(
  202.       _ObjectID,
  203.       _ScriptClass,
  204.       _ComponentID,
  205.       _Matrix);
  206.   }
  207.  
  208.   void UnitComeHere(string _ObjectID)
  209.   {
  210.     //Core_LogMessage("UnitComeHere");
  211.  
  212.     // call script user's function
  213.     MissionEditorUnitComeHere(_ObjectID);
  214.   }
  215.  
  216.   void ChangeID(string _OldID, string _NewID)
  217.   {
  218.     // call script user's function
  219.     MissionEditorChangeID(_OldID, _NewID);
  220.   }
  221.  
  222.   void SetBehaviorScript(string _ID, string _ScriptClass)
  223.   {
  224.     // call script user's function
  225.     MissionEditorSetBehaviorScript(_ID, _ScriptClass);
  226.   }
  227.  
  228.   void SetCustomParameter(string _ObjectID, string _CustomParameter)
  229.   {
  230.     // call script user's function
  231.     MissionEditorSetCustomParameter(_ObjectID, _CustomParameter);
  232.   }
  233. }
  234.  
  235.  
  236.  
  237.  
  238. class CCockpitTargetingCameraLink extends CInteriorMeshObjectPrefix
  239. {
  240.   final string g_DefaultTarget = "Helicopter";
  241.  
  242.   void CCockpitTargetingCameraLink()
  243.   {
  244.     SetCameraCollisionRadius(10.0);
  245.     SelectTargetObject(g_DefaultTarget);
  246.   }
  247.  
  248.   float m_OnLostDistance = 20.0;
  249.   float m_OnLostRotSpeed = 0.0;
  250.  
  251.   void ShowTargetObject(
  252.       string _TargetId,
  253.       float  _Distance,
  254.       float  _RotSpeed
  255.     )
  256.   {
  257.     if ("" == _TargetId)
  258.       _TargetId = g_DefaultTarget;
  259.  
  260.     SetCameraPosition(vector(0.0, 0.0, 2.0), vector(0.0, 0.0, 2.0), _Distance);
  261.     SetCameraRotation(rand(Math_PI), _RotSpeed);
  262.  
  263.     m_OnLostDistance = _Distance;
  264.     m_OnLostRotSpeed = _RotSpeed;
  265.  
  266.     SetTargetObjectId(_TargetId);
  267.   }
  268.  
  269.   void ShowTargetPoint(
  270.       vector _Point,
  271.       float  _Distance,
  272.       float  _RotSpeed,
  273.       bool   _PutOnTer
  274.     )
  275.   {
  276.     SetCameraPosition(vector(0.0, 0.0, 50.0), vector(0.0, 0.0, 10.0), _Distance);
  277.     SetCameraRotation(rand(Math_PI), _RotSpeed);
  278.  
  279.     m_OnLostDistance = _Distance;
  280.     m_OnLostRotSpeed = _RotSpeed;
  281.  
  282.     SetTargetPoint(_Point, _PutOnTer);
  283.   }
  284.  
  285.  
  286.   void SelectTargetObject(
  287.       string _TargetId
  288.     )
  289.   {
  290.     ShowTargetObject(_TargetId, 20.0, 0.0);
  291.  
  292.     m_OnLostDistance = 50.0;
  293.     m_OnLostRotSpeed = Math_PI * 0.05;
  294.   }
  295.  
  296.   void SelectNavigationPoint(
  297.       vector _Point
  298.     )
  299.   {
  300.     ShowTargetPoint(_Point, 200.0, Math_PI * 0.05, true);
  301.   }
  302.  
  303.  
  304.   string m_MissileTargetId = "";
  305.  
  306.   void SelectMissileAsTarget(
  307.       int    _BulletId,
  308.       string _TargetId
  309.     )
  310.   {
  311.     LinkCameraToTarget(vector(10.0, 0.0, 0.0), vector(1000.0, 0.0, 0.0));
  312.  
  313.     m_MissileTargetId = _TargetId;
  314.     SetTargetBulletId(_BulletId);
  315.   }
  316.  
  317.   void OnLostTargetObject(
  318.       string _LinkMode,
  319.       string _TargetId,
  320.       matrix _Position
  321.     )
  322.   {
  323.     if ((TLM_Object == _LinkMode) &&
  324.         IsInteriorObjectId(_TargetId))
  325.     {
  326.       SelectTargetObject(g_DefaultTarget);
  327.       return;
  328.     }
  329.  
  330.     SetCameraPosition(vector(0.0, 0.0, 10.0), vector(0.0, 0.0, 5.0), m_OnLostDistance);
  331.     SetCameraRotation(rand(Math_PI), m_OnLostRotSpeed);
  332.  
  333.     if (TLM_Object == _LinkMode)
  334.     {
  335.       SetTargetObjectId(ConvertIdToInteriorId(_TargetId));
  336.     }
  337.     else
  338.     if (TLM_Bullet == _LinkMode)
  339.     {
  340.       if ("" != m_MissileTargetId)
  341.         SelectTargetObject(m_MissileTargetId);
  342.       else
  343.         SetTargetPoint(Core_GetMatrixOrigin(_Position), true);
  344.     }
  345.   }
  346. }
  347.  
  348. class CCockpitTargetingCamera
  349. {
  350.   final float hor_size = 0.2;
  351.   final float m_ScreenRectLeft   = 1.0 - 0.01 - hor_size;
  352.   final float m_ScreenRectTop    = 0.01 / 0.75;
  353.   final float m_ScreenRectRight  = 1.0 - 0.01;
  354.   final float m_ScreenRectBottom = (0.01 + hor_size) / 0.75;
  355.  
  356.   float FOV        = 1.0;
  357.  
  358.   float RectLeft   = m_ScreenRectLeft;
  359.   float RectTop    = m_ScreenRectTop;
  360.   float RectRight  = m_ScreenRectRight;
  361.   float RectBottom = m_ScreenRectBottom;
  362.  
  363.   float ZMin       = 0.0;
  364.   float ZMax       = 1.0;
  365.   float ZNear      = 1.0;
  366.   float ZFar       = 100.0;
  367.  
  368.   float Priority   = 1;
  369.  
  370.   void CCockpitTargetingCamera()
  371.   {
  372.     Core_AddClassificator(CLASSIFICATOR_LOW_DETAIL_CAMERA);
  373.   }
  374.  
  375.   void SetTargetingCameraViewMode(
  376.       string _ViewMode
  377.     )
  378.   {
  379.     if ("FullScreen" == _ViewMode)
  380.     {
  381.       SetRenderRectangle(0.0, 0.0, 1.0, 1.0);
  382.       Core_RemoveClassificator(CLASSIFICATOR_LOW_DETAIL_CAMERA);
  383.     }
  384.     else
  385.     {
  386.       SetRenderRectangle(m_ScreenRectLeft, m_ScreenRectTop,
  387.                          m_ScreenRectRight, m_ScreenRectBottom);
  388.       Core_AddClassificator(CLASSIFICATOR_LOW_DETAIL_CAMERA);
  389.     }
  390.   }
  391. }
  392.  
  393. class CCockpitTargetingScreen
  394. {
  395.   void CCockpitTargetingScreen()
  396.   {
  397.     CreateComponent("Camera", "Camera", "CCockpitTargetingCamera");
  398.     SetCompoundObjectPositionable("Camera");
  399.  
  400.     CreateComponent("Control", "ShowObjectCameraControl", "CCockpitTargetingCameraLink");
  401.     SetComponentSlaveObject("Control", "Camera");
  402.  
  403.     Core_AddClassificator(CLASSIFICATOR_NOTVISIBLEONRADAR);
  404.   }
  405. }
  406.  
  407.  
  408.  
  409.  
  410. class CHelicopterCockpit extends CCockpit
  411. {
  412.   void CHelicopterCockpit()
  413.   {
  414.     // altimeter
  415.     CreateAltimeter("MainAltimeter", true);
  416.  
  417.     // damage, etc. bar
  418.     CreateSelfBar(
  419.       "MainSelfBar",
  420.       true,
  421.       0.02 + 0.16,
  422.       1.0 - (0.01 + 0.16) / 0.75,
  423.       0.017,
  424.       0.16 / 0.75
  425.     );
  426.  
  427.     ShowDamage("MainSelfBar", 100);
  428.  
  429.     // weapon bar
  430.     CreateWeaponBar(
  431.       "WeaponBar",
  432.       true,
  433.       0.01,                               // x
  434.       1.0 - (0.16 + 0.01) / 0.75 - 0.05,  // y
  435.       0.10,                               // width
  436.       0.05                                // height
  437.     );
  438.   }
  439.  
  440.   // initialize cocpit on mission loaded
  441.   void OnMissionLoaded()
  442.   {
  443.     InitializeCockpit();
  444.  
  445.     Core_CallFunction(
  446.         SOID_MissionController,
  447.         "CreateComponent",
  448.         "CockpitTargetingScreen",
  449.         "GameObject",
  450.         "CCockpitTargetingScreen"
  451.       );
  452.   }
  453.  
  454.   void OnHitpointsWasChanged(
  455.       float _HPPercent
  456.     )
  457.   {
  458.     ShowDamage("MainSelfBar", int(100.0 * _HPPercent));
  459.   }
  460.  
  461.   void OnEnableControl(
  462.       bool _Enable
  463.     )
  464.   {
  465.     UpdateTargetingScreenState();
  466.   }
  467.  
  468.   void OnEnableTargetScreen(
  469.       bool _Enable
  470.     )
  471.   {
  472.     UpdateTargetingScreenState();
  473.   }
  474.  
  475.   bool m_ShowTargetScreen = true;
  476.   void SetCocpitRenderMode(
  477.       string _RenderMode
  478.     )
  479.   {
  480.     SetRenderMode(_RenderMode);
  481.     if (CRM_Cocpit == _RenderMode)
  482.       m_ShowTargetScreen = true;
  483.     else
  484.       m_ShowTargetScreen = false;
  485.  
  486.     UpdateTargetingScreenState();
  487.   }
  488.  
  489.   bool m_FullScreenMode = false;
  490.  
  491.   void OnSetCameraView(
  492.       int _ViewType
  493.     )
  494.   {
  495.     if (CVT_DefaultView == _ViewType)
  496.       m_FullScreenMode = false;
  497.     else
  498.     if (CVT_NextView == _ViewType)
  499.       m_FullScreenMode = false;
  500.     else
  501.     if (CVT_TargetView == _ViewType)
  502.       m_FullScreenMode = !m_FullScreenMode;
  503.  
  504.  
  505.     string ScreenMode = "CockipScreen";
  506.     if (m_FullScreenMode)
  507.       ScreenMode = "FullScreen";
  508.  
  509.     Core_SendEventTo(
  510.         "CockpitTargetingScreen",
  511.         "SetTargetingCameraViewMode",
  512.         ScreenMode
  513.       );
  514.  
  515.     Core_CallFunction(
  516.         SOID_GameController,
  517.         "ActivateCamera",
  518.         "Helicopter",
  519.         !m_FullScreenMode
  520.       );
  521.  
  522.     UpdateTargetingScreenState();
  523.   }
  524.  
  525.   void UpdateTargetingScreenState()
  526.   {
  527.     Core_CallFunction(
  528.         SOID_GameController,
  529.         "ActivateCamera",
  530.         "CockpitTargetingScreen",
  531.         (IsControlEnabled() &&
  532.          IsTargetScreenEnabled() &&
  533.          m_ShowTargetScreen) ||
  534.         m_FullScreenMode
  535.       );
  536.   }
  537.  
  538.   void OnTargetSelected(
  539.       string _TargetId
  540.     )
  541.   {
  542.     Core_SendEventTo(
  543.         "CockpitTargetingScreen",
  544.         "SelectTargetObject",
  545.         _TargetId
  546.       );
  547.   }
  548.  
  549.   void OnNavPointSelected(
  550.       vector _NavPoint
  551.     )
  552.   {
  553.     Core_SendEventTo(
  554.         "CockpitTargetingScreen",
  555.         "SelectNavigationPoint",
  556.         _NavPoint
  557.       );
  558.   }
  559.  
  560.   void OnWeaponFire(
  561.       int    _BulletId,
  562.       string _TargetId
  563.     )
  564.   {
  565.     Core_SendEventTo(
  566.         "CockpitTargetingScreen",
  567.         "SelectMissileAsTarget",
  568.         _BulletId,
  569.         _TargetId
  570.       );
  571.   }
  572.  
  573.   void ShowEventObject(
  574.       string _ObjectId,
  575.       float  _Distance
  576.     )
  577.   {
  578.     Core_SendEventTo(
  579.         "CockpitTargetingScreen",
  580.         "ShowTargetObject",
  581.         _ObjectId,
  582.         _Distance,
  583.         Math_PI * 0.05
  584.       );
  585.   }
  586.  
  587.   void ShowEventPoint(
  588.       vector _Point,
  589.       float  _Distance
  590.     )
  591.   {
  592.     Core_SendEventTo(
  593.         "CockpitTargetingScreen",
  594.         "ShowTargetPoint",
  595.         _Point,
  596.         _Distance,
  597.         Math_PI * 0.05,
  598.         true
  599.       );
  600.   }
  601.  
  602.   void ShowEventPoint(
  603.       vector _Point,
  604.       float  _Distance,
  605.       bool   _PutOnTer
  606.     )
  607.   {
  608.     Core_SendEventTo(
  609.         "CockpitTargetingScreen",
  610.         "ShowTargetPoint",
  611.         _Point,
  612.         _Distance,
  613.         Math_PI * 0.05,
  614.         _PutOnTer
  615.       );
  616.   }
  617.  
  618.   void OnInitiallyEnableTargetScreen(
  619.       bool _enable
  620.     )
  621.   {
  622.     EnableTargetScreen(_enable);
  623.   }
  624.  
  625.   bool OnIsTargetScreenEnabled()
  626.   {
  627.     return IsTargetScreenEnabled();
  628.   }
  629. }
  630.  
  631.  
  632.